﻿using System.IO;
using System.Reflection;

namespace Borg.AttributeAnalyze.Result
{
    public abstract class ResultBase
    {
        protected ExtensionTypeInfo ExtensionTypeInfo;
        protected RepositoryMetaElement RepositoryElement;

        protected ResultBase(FileInfo file, Component component, ResultType result)
        {
            AnalyzedFile = file;
            Component = component;
            Result = result;
        }

        protected ResultBase(Assembly assembly, Component component, ResultType result,
            RepositoryMetaElement repositoryElement, ExtensionTypeInfo extensionTypeInfo)
        {
            AnalyzedAssembly = assembly;
            Component = component;
            Result = result;
            RepositoryElement = repositoryElement;
            ExtensionTypeInfo = extensionTypeInfo;

            if (assembly != null)
                AnalyzedFile = new FileInfo(assembly.Location);
        }

        protected static string GetWhiteSpace(int numberOf)
        {
            return new string(' ', numberOf);
        }

        public abstract string ToMsBuildMessageString();

        public Assembly AnalyzedAssembly { get; private set; }

        public FileInfo AnalyzedFile { get; private set; }

        public Component Component { get; private set; }

        public abstract MessageType MessageType { get; }

        public string Name
        {
            get
            {
                return RepositoryElement == null
                    ? null
                    : RepositoryElement.Name;
            }
        }

        public ResultType Result { get; protected set; }

        public virtual string TypeName
        {
            get
            {
                return ExtensionTypeInfo == null
                    ? null
                    : ExtensionTypeInfo.TypeName;
            }
        }
    }
}

